import { merge } from "@/utils/core"
import { ElMessageBox, ElMessageBoxOptions, IElMessageBox, MessageBoxData } from "element-plus"
export declare interface HElMessageBox {
    alert: (message: string, title: string, options: ElMessageBoxOptions) => Promise<MessageBoxData>
    confirm: (message: string, title: string, options: ElMessageBoxOptions) => Promise<MessageBoxData>
    prompt: (message: string, title: string, options: ElMessageBoxOptions) => Promise<MessageBoxData>
}

export const useElMessageBox = (): HElMessageBox => {
    const defaultOptions = {
        autofocus: true, // 自动获取焦点
        dangerouslyUseHTMLString: false, // 将message作为HTML片段处理（注意：开启时需防止SSR注入）
        type: 'info',  // 默认为提示信息, 可选：success、warning、error
        showClose: true, // 显示右上角关闭按钮
        callback: () => messageBoxCloseCallback, // 回调
    }
    const messageBoxCloseCallback = (action: string, instance: IElMessageBox): void => {
        if (action === 'confirm') {
        }
    }
    return {
        alert: (message, title, options = {}) => {
            return ElMessageBox.alert(message, title, merge(options, defaultOptions))
        },
        confirm: (message, title, options = {}) => {
            return ElMessageBox.confirm(message, title, merge(options, defaultOptions))
        },
        prompt: (message, title, options = {}) => {
            return ElMessageBox.prompt(message, title, merge(options, defaultOptions))
        }
    }
}